package org.aeon.gamechatnest.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.aeon.gamechatnest.common.response.Result;
import org.aeon.gamechatnest.common.response.ResultBuild;
import org.aeon.gamechatnest.pojo.FriendRequest;
import org.aeon.gamechatnest.service.FriendRequestService;
import org.aeon.gamechatnest.validated.Add;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 好友请求控制器
 *
 * @author : Qik 2024/5/9 10:42
 */
@Validated
@RestController
@RequestMapping("/friend/request")
@Tag(name = "FriendRequestControllerApi", description = "好友请求控制器类API")
public class FriendRequestController {
    @Autowired
    private FriendRequestService friendRequestService;

    @Operation(
            summary = "新增一个好友请求",
            description = "增一个好友请求"
    )
    @PostMapping
    public Result addFriendRequest(@RequestBody @Validated(Add.class) FriendRequest friendRequest) {
        boolean save = friendRequestService.save(friendRequest);
        return ResultBuild.successIf(save).build();
    }

    @Operation(
            summary = "获取一个好友请求",
            description = "根据id获取一个好友请求实体并返回json",
            parameters = {@Parameter(name = "id", description = "好友请求id编号")}
    )
    @GetMapping("/{id}")
    public Result getFriendRequest(@PathVariable("id") Long id) {
        FriendRequest res = friendRequestService.find(id);
        return ResultBuild.successIf(res != null, res).build();
    }

    @Operation(
            summary = "查询当前用户接受到的好友请求",
            description = "获取接受到的好友请求列表，只查未通过的"
    )
    @GetMapping("/receive")
    public Result getReceiveFriendRequestList() {
        List<FriendRequest> friendRequests = friendRequestService.findReceive();
        return ResultBuild.result().successful().data(friendRequests).build();
    }
}
